#include "Function.hpp"

namespace minnet
{
	namespace function
	{
		Tensor MSELoss(const Tensor& pred, const Tensor& real) {
			return (pred - real).pow(2.f).rowsum();
		}

		Tensor NLLLoss(const Tensor& pred, const Tensor& real) {
			return -(real * pred).rowsum();
		}

		Tensor CrossEntropyLoss(const Tensor& pred, const Tensor& real) {
			return NLLLoss(SoftMax(pred).log(), real);
		}

		Tensor Relu(const Tensor& tensor) {
			return tensor.relu();
		}

		Tensor Sigmoid(const Tensor& tensor) {
			return tensor.sigmoid();
		}

		Tensor Tanh(const Tensor& tensor) {
			return tensor.tanh();
		}

		Tensor SoftMax(const Tensor& tensor) {
			Tensor exp = (tensor - tensor.max()).rpow(E);
			return exp / exp.rowsum();
		}

		Tensor MaxPool2d(const Tensor& tensor, int size) {
			return tensor.maxpool2d(size);
		}
	} // namespace function
} // namespace minnet
